package com.spring.context.support;

import com.spring.beans.BeansException;
import com.spring.beans.factory.support.DefaultListableBeanFactory;

/**
 * @Description: This is a sample class.
 * @Author: Simon
 */
public abstract class AbstractRefreshableApplicationContext extends AbstractApplicationContext {

    private DefaultListableBeanFactory beanFactory;

    //创建BeanFactory并加载BeanDefinition
    protected final void refreshBeanFactory() throws BeansException{
        DefaultListableBeanFactory beanFactory = createBeanFactory();
        loadBeanDefinitions(beanFactory);
        this.beanFactory=beanFactory;
    }

    //创建bean工厂
    protected DefaultListableBeanFactory createBeanFactory(){
        return new DefaultListableBeanFactory();
    }

    protected abstract void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException;


    @Override
    public DefaultListableBeanFactory getBeanFactory() {
        return beanFactory;
    }
}
